package com.share.barter.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author  Tumi
 * 日期：2012-11-13
 */
public class LoginAction extends ActionSupport {

	private String username;
	private String password;
	
	//登陆
	public String execute() throws Exception{
		
			if(getUsername().equals("root") && getPassword().equals("root")){
				//将User信息放入到session中
				ActionContext.getContext().getSession().put("user",getUsername());
				return "success";
			}else{
				return "error";
			}
	}
	//数据验证
	public void validate(){
		if(getUsername() == null || getUsername().trim().equals("")){
			addFieldError("username","user.required");
		}
		if(getPassword() == null || getPassword().trim().equals("")){
			addFieldError("password","password.required");
		}
	}
	
	
	
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}

	
}
